package com.gscitysfy.cus.drain.modules.template.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.reserveplan.entity.DrainReservePlanControlInfo;
import com.gscitysfy.cus.drain.modules.reserveplan.entity.DrainReservePlanInfo;
import com.gscitysfy.cus.drain.modules.reserveplan.vo.DrainReservePlanInfoVo;
import com.gscitysfy.cus.drain.modules.template.entity.DrainTemplateInfo;
import com.gscitysfy.cus.drain.modules.template.service.IDrainTemplateInfoService;
import com.gscitysfy.cus.drain.modules.template.vo.DrainTemplateInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shenglin
 * @since 2022-11-16 14:09:26
 */
@RestController
@RequestMapping("/template/drain-template-info")
@Tag(name = "模板管理")
public class DrainTemplateInfoController {

    @Resource
    IDrainTemplateInfoService drainTemplateInfoService;


    /**
     * 新增或修改模板
     *
     * @param drainTemplateInfo
     * @return
     */
    @PostMapping("/saveOrUpdateTemplateInfo")
    @Operation(summary = "新增或修改模板", description = "新增或修改模板")
    public Result saveOrUpdateTemplateInfo(@RequestBody DrainTemplateInfo drainTemplateInfo) {
        return Result.content(drainTemplateInfoService.saveOrUpdate(drainTemplateInfo));
    }

    /**
     * 根据ID删除模板
     *
     * @param ids
     * @return
     */
    @PostMapping("/deleteTemplateInfo")
    @Operation(summary = "根据ID删除模板", description = "根据ID删除模板")
    @Parameters({
            @Parameter(name = "ids", description = "ID", example = "1", required = true)
    })
    public Result deleteTemplateInfo(@RequestBody List<String> ids) {
        return Result.content(drainTemplateInfoService.deleteTemplateInfo(ids));
    }


    /**
     * 分页获取模板信息列表
     *
     * @param drainTemplateInfoVo
     * @return
     */
    @PostMapping("/getTemplateInfoList")
    @Operation(summary = "分页获取模板信息列表", description = "分页获取模板信息列表")
    @Parameters({
            @Parameter(required = false, name = "templateKind", description = "模板种类,险情模板和调度指令模板"),
            @Parameter(required = false, name = "templateType", description = "模板类型"),
            @Parameter(required = false, name = "templateName", description = "模板名称"),
            @Parameter(required = false, name = "templateStatus", description = "模板启用状态"),
            @Parameter(required = false, name = "templateDesc", description = "模板内容"),
            @Parameter(required = false, name = "cmStartAddTime", description = "添加开始时间"),
            @Parameter(required = false, name = "cmEndAddTime", description = "添加结束时间"),
            @Parameter(required = false, name = "current", description = "当前页码"),
            @Parameter(required = false, name = "size", description = "每页显示条数")
    })
    @DictTranslation({
            @FieldParam(dictType = DicConstant.TEMPLATE_DANGER_TYPE, targetField = "templateType"),
            @FieldParam(dictType = DicConstant.TEMPLATE_DIAODU_TYPE, targetField = "templateDispatchType"),
    })
    public Result<IPage<DrainTemplateInfo>> getTemplateInfoList(@RequestBody DrainTemplateInfoVo drainTemplateInfoVo) {
        IPage<DrainTemplateInfo> drainReservePlanInfoListByCondition = drainTemplateInfoService.getTemplateInfoList(drainTemplateInfoVo);
        return Result.content(drainReservePlanInfoListByCondition);
    }


    /**
     * 获取模板详情信息
     *
     * @param id
     * @return
     */
    @PostMapping("/getTemplateInfo")
    @Operation(summary = "获取模板详情信息", description = "获取模板详情信息")
    @Parameters({
            @Parameter(required = true, name = "id", description = "模板id"),
    })
    public Result getReservePlanMnCarList(String id) {
        return Result.content(drainTemplateInfoService.getById(id));
    }

    /**
     * 根据模板生成内容
     *
     * @param templateId
     * @param warnType
     * @param warnAddress
     * @param discoveryTime
     * @return
     */
    @GetMapping("/getInfoByTemplate")
    @Operation(summary = "根据模板生成内容", description = "根据模板生成内容")
    @Parameters({
            @Parameter(required = true, name = "templateId", description = "模板id"),
            @Parameter(required = true, name = "warnType", description = "险情类别"),
            @Parameter(required = true, name = "warnAddress", description = "险情地址"),
            @Parameter(required = true, name = "discoveryTime", description = "发现时间"),
    })
    public Result getInfoByTemplate(String templateId, String warnType, String warnAddress, String discoveryTime) {
        return Result.content(drainTemplateInfoService.getInfoByTemplate(templateId,warnType,warnAddress,discoveryTime));
    }

}
